﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BISPOS.Repository
{
    public class SupplierRepository
    {
        BISPOSDataClassesDataContext db = new BISPOSDataClassesDataContext();

        public void AddSupplier(string name, string address, string telephone, string fax)
        {
            db.Suppliers.InsertOnSubmit(new Supplier
            {
                Address = address,
                Fax = fax,
                Name = name,
                Telephone = telephone
            });
            db.SubmitChanges();
        }
        public Supplier GetSupplie(int id) { return db.Suppliers.FirstOrDefault(x => x.Id == id); }
        public IEnumerable<Supplier> AllSupplier()
        {
            return db.Suppliers;
        }
        public void EditSupplier(int id,string name,string address,string telephone,string fax)
        {
            Supplier supplier = GetSupplie(id);
            supplier.Name = name;
            supplier.Address = address;
            supplier.Telephone = telephone;
            supplier.Fax = fax;
            Save();
        }
        public void Save() { db.SubmitChanges(); }
    }
}
